<template>
  <div class="body">
    <header class="header">
      <div class="title">
        <img src="../../../assets/images/01_11.png" alt class="img_zuo" @click="fanhui" />
        <div>巡查排查</div>
      </div>
    </header>
    <div class="contant" v-if="list!=null">
      <div class="list">
        <div>街道</div>
        <div class="list_two">{{list.streetName}}</div>
      </div>
      <div class="list">
        <div>社区</div>
        <div class="list_two">{{list.communityName}}</div>
      </div>
      <div class="list">
        <div>建筑名称</div>
        <div class="list_two jianhouse">
          <div>{{list.constructionName}}</div>
          <img v-if="list.constructionName=''" class="img_house" src="../../../assets/images/house.png" />
        </div>
      </div>
      <div class="list">
        <div>单位名称</div>
        <div class="list_two">{{list.dwMc}}</div>
      </div>
      <div class="list">
        <div>类别</div>
        <div class="list_two">{{list.typeName}}</div>
      </div>
      <div class="list">
        <div>地址</div>
        <div class="list_two">{{list.address}}</div>
      </div>
      <div class="list">
        <div>负责人</div>
        <div class="list_two">{{list.person}}</div>
      </div>
      <div class="list">
        <div>联系电话</div>
        <div class="list_two">{{list.phone}}</div>
      </div>
      <div class="list">
        <div>巡查记录</div>
        <div class="list_two">{{list.count}}</div>
      </div>
      <div @click="nextgo" class="button" v-show="isShow===1">
        <img class="img_hand" src="../../../assets/images/hand.png" />
        <div>生成巡查清单</div>
      </div>
    </div>
    <div class="ditu yc" id="map">
      <div id="ditu"></div>
      <div class="lie_list"></div>
    </div>
  </div>
</template>

<script>
  import { Toast } from 'vant';
  export default {
    name: "inspect_detail",
    data() {
      return {
        list: null,
        userId:2824,//用户id
        id:24046,
        type: 2,//类型
        isShow:null,
        map:null
      };
    },
    methods: {
      fanhui() {
        let a = localStorage.getItem("shengchengxuncha")
        console.log(a)
        try{
          var _map = plus.maps.getMapById('ditu');
          if(_map){
            _map.close();
          }
        }catch(e){
          //TODO handle the exception
        }
        this.$router.back();
      },
      nextgo() {
        var _this = this;
        sessionStorage.removeItem('detailsession');
        _this.axios
          .get(_this.$global_msg.Url.host + "/Xx/insertPatrolTroubleshoot?id=" + _this.id + "&userId=" + _this.userId + "&type=" + _this.type)
          .then(res => {
            console.log(res);
            if (res.data.code == 0) {
              _this.getDwInfo(_this.list.id,'jxmd',_this.list.map,function(){
                try{
                  var _map = plus.maps.getMapById('ditu');
                  if(_map){
                    _map.close();
                  }
                }catch(e){
                  //TODO handle the exception
                }
                localStorage.removeItem('param_fgd');
                localStorage.removeItem('busheji_list');
                localStorage.setItem("patrolTroubleshootId",res.data.rows.patrolTroubleshootId);
                let xcdx_map_xcdxObj = {
                  id: _this.list.id,
                  mc: _this.list.dwMc,
                  s_type_mc: _this.list.typeName,
                  b_type: 'jxmd'
                }
                localStorage.setItem('xcdx_map_xcdxObj', JSON.stringify(xcdx_map_xcdxObj))
                localStorage.setItem("type", _this.type);
                _this.$router.push("/detail_list");
              });
            } else {
              _this.$toast(res.data.msg)
            }
          }).catch(error => {
            this.$terminal._error(error)
          });
      },
      listarry() {
        try {
          plus.nativeUI.showWaiting("正在加载...");
        } catch (e) {
          console.log('plus问题');
        }
        this.axios.get(
            `${this.$global_msg.Url.host}/Xx/selectPatrolTroubleshoot?id=${this.id}&userId=${this.userId}&type=${this.type}`
          ).then(res => {
            try {
              plus.nativeUI.closeWaiting();
            } catch (e) {
              console.log('plus问题');
            }
            console.log(res);
            if (res.data.code == 200) {
              this.list = res.data.rows.PatrolInfo;
              console.log(JSON.stringify(res.data.rows))
              this.isShow = res.data.rows.isShow;
              //this.isShow = 1;
            } else if(res.data.code ==-1) {
              Toast({
                message: res.data.rows,
                onClose: _ => {
                  this.$router.push("/community_list");
                }
              })
            }else{
              this.$toast(res.data.msg);
            }
          }).catch(error => {
            this.$terminal._error(error)
          });

      },
      getmap(){
        this.map = new plus.maps.Map("ditu");
      },
      getDwInfo(id,type,jwd,func){
        var _this = this;
        try{
          plus.nativeUI.showWaiting("正在加载...");
        }catch(e){
          console.log(e.message);
        }
        var dw_timer = setInterval(function(){
          if(_this.map){
            clearInterval(dw_timer);
            _this.map.getUserLocation(function (state, point) {
              // var jwd = point.longitude + "," + point.latitude
              var jwd2 = point.longitude+','+point.latitude;
              var xcpc_da_obj = {
                id:id,
                type:type,
                jwd:jwd2,
                oldjwd:jwd
              };
              localStorage.setItem("xcpc_da_obj",JSON.stringify(xcpc_da_obj));
              try{
                plus.nativeUI.closeWaiting();
              }catch(e){
                console.log(e.message);
              }
              func();
            })
          }
        },100);
      }
    },
    mounted() {
      var _this = this;
      // document.body.style.backgroundColor="#F7F7F9";

      //物理返回
      // window.addEventListener("popstate", function(){
      //   _this.fanhui();
      // }, false);
    },
    created() {
      this.userId = localStorage.getItem("userId"); //  获取访问id
      console.log(this.userId);
      // alert(this.userId)
      let data = JSON.parse(sessionStorage.getItem("scan_canshu_data"));
      // alert("九小"+JSON.stringify(data))
      this.id = data.id;
      this.type = data.type;
      this.listarry();
      this.getmap();
    }
  };
</script>
<style scoped>
  .ditu{
    display: none;
  }
  .list_two {
    color: #8e8e8e;
  }

  .jianhouse {
    display: flex;
    align-items: center;
  }

  .jianhouse img {
    width: 0.4rem;
    margin-left: 0.2rem;
  }

  .list {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f2f2f2;
    height: 1.3rem;
    padding: 0 0.4rem;
  }

  .button img {
    width: 0.6rem;
    margin-right: 0.4rem;
  }

  .button {
    width: 100%;
    height: 1.5rem;
    color: white;
    background-color: #2b6cfe;
    position: absolute;
    bottom: 0.3rem;
    /* left: 5%; */
    border-radius: 0.105185rem;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .contant {
    margin-top: 1.8519rem;
    border: 1px solid white;
  }

  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 20;
    font-size: 0.388888rem;
  }

  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
  }

  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }

  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }
</style>
